define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user_cards/index' + location.search,
                    add_url: 'user/user_cards/add',
                    edit_url: 'user/user_cards/edit',
                  //  del_url: 'user/user_cards/del',
                    multi_url: 'user/user_cards/multi',
                    import_url: 'user/user_cards/import',
                    table: 'user_cards',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                       /// {field: 'user_id', title: __('User_id')},
                       // {field: 'goods_id', title: __('Goods_id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'business.business_name', title: __('企业名称'), operate: 'LIKE'},
                       // {field: 'order_id', title: __('Order_id')},
                        {field: 'type', title: __('类型'), searchList: {"1":__('购买激活'),"2":__('卡密激活')}, formatter: Table.api.formatter.status},

                        {field: 'rights_card', title: __('Rights_card'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'rights_title', title: __('Rights_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'rights_nums', title: __('Rights_nums')},
                        {field: 'can_uses', title: __('Can_uses')},
                        {field: 'used_nums', title: __('Used_nums')},
                        {field: 'status', title: __('状态'), formatter: Table.api.formatter.status, searchList: {'1': __('使用中'), '2': __('已使用'),'3': __('已退款'),'4': __('已过期')}},
                        {field: 'rights_endtime', title: __('Rights_endtime'),operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime,
                            datetimeFormat: "YYYY-MM-DD"},
                      //  {field: 'rights_content', title: __('Rights_content')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                       // {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
